﻿#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, d;
    cin >> n >> d;

    vector<vector<int>> Q(n, vector<int>(d));//输入的矩阵
    vector<vector<int>> K(n, vector<int>(d));
    vector<vector<int>> V(n, vector<int>(d));
    vector<int> W(n);//输入的向量

    //获得Q
    for (int i = 0; i < n; i++)
        for (int j = 0; j < d; j++)
            cin >> Q[i][j];

    //获得矩阵K
    for (int i = 0; i < n; i++)
        for (int j = 0; j < d; j++)
            cin >> K[i][j];

    // 获得矩阵K
    for (int i = 0; i < n; i++)
        for (int j = 0; j < d; j++)
            cin >> V[i][j];

    // 获取向量W
    for (int i = 0; i < n; i++)
        cin >> W[i];

    //实现Q*K^T
    vector<vector<int>> QKT(n, vector<int>(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            for (int k = 0; k < d; k++) {
                QKT[i][j] += Q[i][k] * K[j][k];
            }
        }
    }

    //实现 (W ⋅ (Q * K^T)) × V
    vector<vector<int>> result(n, vector<int>(d, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            // 计算结果
            for (int k = 0; k < n; k++) {
                result[i][j] += (W[i] * QKT[i][k]) * V[k][j];
            }
        }
    }

    //输出
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            if (j > 0) cout << " ";
            cout << result[i][j];
        }
        cout << endl;
    }

    return 0;
}